import { default as jsCookie } from 'js-cookie'
import axios from 'axios'
import { useStore } from '@/store'
const baseUrl = import.meta.env.VITE_APP_BASE_REQUEST
let store: any
export interface baseResponse<T> {
  code: string,
  msg: string,
  data: T
}

const request = axios.create({
  baseURL: baseUrl as string,
  timeout: 5000
})
const white = ['/index/login']
request.interceptors.request.use((config: any) => {
  config.headers['Content-Type'] = 'application/json;charset=utf-8';
  if (white.includes(config.url as string)) {
    return config
  }
  // if (!store) store = useStore()
  let userToken: string = jsCookie.get("userToken") as string
  let token: string = userToken
  config.headers['Authorization'] = token
  return config

})
request.interceptors.response.use((res: any) => {
  if (res.data) {
    return res.data
  }
  return res
})
export default request

